<template>
	<view class='contents'>
		<view class="body">
			<uni-forms :value="formData" :rules="rules" ref="form">
				<!-- <uni-group>
					<uni-forms-item label="家庭信息采集" required labelWidth="200" name="" labelPosition="top">
						<view class="qm">
							<view class="qm_btn">
								<button type="primary" @click="startCatch">{{vk.getVuex('$app.isCatch')?'修改采集信息':'开始采集'}}</button>
							</view>
						</view>
					</uni-forms-item>
				</uni-group> -->
				
				<uni-group>
					<view class="">
						<!-- <text>你可能需要提交的材料有：\n</text>
						<text style="color: #DD524D;">1.户口本户主页
							2.本人身份证
							3.家庭成员户口本
							
							{{material}}
							N.其他\n
						</text> -->
					</view>

					<!-- <uni-forms-item label="证明材料自查" name="material" required labelWidth="200" labelPosition="top">
						<text style="color: #DD524D;font-size: 16px;">
							请选择或填写您所提交的证明材料名称\n
						</text>
						<uni-data-checkbox multiple v-model="formData.material" :localdata="materialData">
						</uni-data-checkbox>
					</uni-forms-item> -->
					
					<!-- <uni-forms-item label="" name="otherMaterial">
						<uni-easyinput type="textarea" v-model="formData.otherMaterial" placeholder="其他证明">
						</uni-easyinput>
					</uni-forms-item> -->

					<!-- <uni-forms-item  label="证明材料上传"  required labelWidth="200" name="" labelPosition="top">
						<uni-file-picker ref="files" :readonly="isreadonly" :auto-upload="false" style="text-align: center;" limit="50" mode="grid" fileMediatype="image" 
							@success="success" @delete="delete_file" @select="select"/>
							<button @click="upload" style="margin-top: 5px;" size="mini" type="primary">{{uploadText}}</button>
					</uni-forms-item> -->



				</uni-group>

				<uni-group>
					<uni-forms-item label="学生本人签名" required labelWidth="120" name="" labelPosition="top">
						<view class="qm">
							<view class="qm_btn">
								<button type="primary" @click="state=startgraph('stu')">签名</button>
							</view>
						</view>
					</uni-forms-item>

				</uni-group>


				<!-- <uni-group>
					<uni-forms-item label="学生家长或监护人签名" required labelWidth="200" name="" labelPosition="top">
						<view class="qm">
							<view class="qm_btn">
								<button type="primary" @click="startgraph('par')">签名</button>
							</view>
						</view>
					</uni-forms-item>
					
				</uni-group> -->

				

				<uni-group title=" " margin-top="">
					<view class="warn">
						<text style="margin-left: 20px;">请保证所填写资料真实、准确，并同意授权相关部门通过信息核对，对所填资料进行查询、核对。</text>
					</view>

					<view class="warn">
						<text style="margin-left: 20px;color: #DD524D;">如虚报材料，本人愿意承担相关责任</text>
					</view>

					<view class="submit_btn">
						<button type="primary" @click="sub">保存</button>
					</view>
				</uni-group>
			</uni-forms>





		</view>


	</view>
</template>

<script>
	var that;// 当前页面对象
	var vk; //vk依赖
	
	var touchs = [];
	var canvasw = 0;
	var canvash = 0;
	var _that;
	var testNode;
	var form;

	//获取系统信息
	uni.getSystemInfo({
		success: function(res) {
			canvasw = res.windowWidth;
			canvash = res.windowHeight;
		},
	})
	
	import {addKunnanInfo} from "@/api/kunnan.js"
	
	export default {
		data() {
			return {
				filesNum:0,
				isreadonly:false,
				uploadText:'开始上传',
				imageValue: [],
				stu_id: '',
				signImage: '',
				calcel_text: '取消',
				autograph_btn_stu: '签名',
				autograph_btn_par: '签名',
				isEnd: false,
				stu: false,
				par: false,
				status: '',
				autograph: [],
				FilePath: [],
				material: '',
				formData: {
					otherMaterial: '',
					material:''
					// otherMaterial: ''
				},
				rules: {
					material: {
						rules: [{
							required: true,
							errorMessage: '请选择您所有提交材料的名称'
						}]
					}
				},
				materialData: [{
						text: '脱贫家庭相关证件',
						value: 0
					},
					{
						text: '脱贫不稳定家庭相关证件',
						value: 1
					},
					{
						text: '边缘易致贫家庭相关证件',
						value: 2
					},
					{
						text: '广东省户籍建档立卡家庭相关证件',
						value: 3
					},
					{
						text: '特困人员供养证或农村五保供养证书',
						value: 4
					},
					{
						text: '特困职工证',
						value: 5
					},
					{
						text: '城乡居民最低生活保障证',
						value: 6
					},
					{
						text: '低保边缘家庭证或支出型困难家庭证',
						value: 7
					},
					{
						text: '儿童福利证、孤儿等佐证材料',
						value: 8
					},
					{
						text: '残疾军人证或优抚对象抚恤补助登记证',
						value: 9
					},
					{
						text: '残疾人证',
						value: 10
					},
					{
						text: '失业证',
						value: 11
					},
					{
						text: '重大疾病的医生证明(盖医院公章方有效)',
						value: 12
					},
					{
						text: '受灾证明(政府部门开具并盖公章)',
						value: 13
					},
					{
						text: '家庭成员在校证明',
						value: 14
					},
					{
						text: '家庭成员户口簿',
						value: 15
					}
				]
			}
		},
		methods: {
			
			sub() {
				const that = this
				let autograph = ''
				this.$refs.form.validate().then(res => {
					getApp().globalData.kunnan.autograph = res
					try {
						getApp().globalData.kunnan.autograph.autographStu = vk.getVuex('$app.autographStu')
						uni.setStorageSync('kunnan_info',getApp().globalData.kunnan)
					}catch(err){
						console.log(err)
					}
					
					if(vk.getVuex('$app.autographStu') == false){
						uni.showToast({
							icon:'none',
							title:'学生本人未签名'
						})
						return
					}
					// if(getApp().globalData.parAutographStatus == false){
					// 	uni.showToast({
					// 		icon:'none',
					// 		title:'学生家长未签名'
					// 	})
					// 	return
					// }
					
					uni.showModal({
						title: '提示',
						content: '是否保存？请务必确保数据准确，这将影响最终评定结果',
						success: (r) =>{
							if (r.confirm) {
								uni.showLoading({
									title: '正在保存,请稍后'
								})
								
								uni.getStorage({
									key: 'kunnan_info',
									success: (e)=> {
										
										if(!e){
											return
										}
										let k = Object.keys(e.data)
										let isd = ['kunnan','familyInfo','autograph']
										for (let var1 in isd) {
											if(!k.includes(isd[var1])){
												vk.alert('缺少参数，请回首页重新填写');
												vk.setVuex('$app.isKunnan',false)
												return
											}
										}
										
										//合并对象
										// 转换json为文本
										e.data.autograph.material = JSON.stringify(e.data.autograph.material)
										
										let  kunnanInfo = {
											...e.data.kunnan,
											...e.data.familyInfo,
											...e.data.autograph,
											autographStu:vk.getVuex('$app.autographStu')
										}
										// 发起请求

										addKunnanInfo(kunnanInfo).then(data =>{
												uni.hideLoading()
												let [err,res] = data
												if(res.data.code == 200){
													vk.toast(res.data.msg, "success", 800); // 修改时间延迟
													setTimeout(function() {
														// vk.reLaunch('/pages/index/index');
														vk.navigateTo('/pages/catch/item');
													}, 850);
													
												}else if(res.data.code == 409){
													
												}
												else {
													vk.alert(res.data.msg||err);
												}
										})
										
										
									},
									fail: function() {
										console.log('失败')
										uni.hideLoading()
									}
								})
							}
						}
					})
					

				}).catch(err => {
					// 表单错误提示
					uni.showModal({
						title: '提示',
						content: err[0].errorMessage,
						showCancel: false
					})

				})

			},
			select(e){
				
				this.filesNum = this.filesNum + this.filesNum.length
			},
			startgraph(i) {
				uni.navigateTo({
					url: '../am/am'
				})
			},
			startCatch(){
				
				if(this.stu_id == ''){
					uni.showModal({
						title:'提示',
						content:'参数错误'
					})
					return
				}
				uni.navigateTo({
					url:'../catch/catch?stu_id='+this.stu_id
				})
			}
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			that = this;
			vk = that.vk
			that.options = options
			
			uni.showLoading({
				title: '加载中'
			})
			uni.getStorage({
				key: 'kunnan_info',
				success: (res) => {
					this.stu_id = res.data.kunnan.stu_id
					
					getApp().globalData.kunnan = res.data
					if(res.data.autograph){
						this.formData = res.data.autograph
						vk.setVuex('$app.autographStu',res.data.autograph.autographStu)
					}
					
					
					
					setTimeout(function() {
						uni.hideLoading();
					}, 300);
					// let i = 0
					// if (res.data.jbqk != undefined && res) {

					// 	for (i; i < res.data.jbqk.type.length; i++) {

					// 		switch (res.data.jbqk.type[i]) {
					// 			case 0:
					// 				// console.log(res.data.jbqk.type[0])
					// 				this.material = this.material.concat(4 + i +
					// 					'.建档立卡证明(扶贫手册、精准扶贫...手册)\n')
					// 				break
					// 			case 1:
					// 				this.material = this.material.concat(4 + i + '.特困供养人员证明\n')
					// 				break
					// 			case 2:
					// 				this.material = this.material.concat(4 + i + '.低保证\n')
					// 				break
					// 			case 3:
					// 				this.material = this.material.concat(4 + i + '.特困职工证\n')
					// 				break
					// 			case 4:
					// 				this.material = this.material.concat(4 + i + '.低收入证\n')
					// 				break
					// 			case 5:
					// 				this.material = this.material.concat(4 + i + '.孤儿证明(儿童福利证...)\n')
					// 				break
					// 			case 6:
					// 				this.material = this.material.concat(4 + i + '.父母不能履行抚养义务证明\n')
					// 				break
					// 			case 7:
					// 				this.material = this.material.concat(4 + i + '.父母一方抚养证明\n')
					// 				break
					// 			case 8:
					// 				this.material = this.material.concat(4 + i + '.优抚对象证明\n')
					// 				break
					// 			case 9:
					// 				this.material = this.material.concat(4 + i + '.因公牺牲警察子女证明\n')
					// 				break
					// 		}
					// 		if (res.data.jbqk.hea.length != 0) {
					// 			this.material = this.material.concat(4 + i++ + '.本人残疾证\n')

					// 		}
					// 		if (res.data.jbqk.diseases.length != 0) {
					// 			this.material = this.material.concat(4 + i++ + '.本人患重大疾病证明\n')

					// 		}
					// 	}
					// 	if (res.data.income != undefined) {
					// 		if (res.data.income.Emergency != undefined) {
					// 			if (res.data.income.Emergency.length != 0) {
					// 				this.material = this.material.concat(4 + i++ +
					// 					'.家庭突发意外事件证明,两年以内重大自然灾害的请提供相应的电视报道截图或县级以上证明\n')
					// 			}


					// 		}
					// 	}
					// }

					// this.material = this.material.concat(4 + i + '.其他证明\n')
					uni.hideLoading();
					setTimeout(function() {

					}, 300);
				},
				fail: (err) => {
					setTimeout(function() {
						uni.hideLoading();
					}, 300);
				}
			})
		},
	}
</script>

<style>
	.ts {
		color: #FF485D;
		font-size: 30upx;
		height: 100upx;
		line-height: 100upx;
		padding-left: 20upx;
	}

	canvas {
		background-color: #fff;
		width: 100vw;
		max-width: 620px;
		/* margin: 0 20rpx; */
		height: 30vh;
		border-radius: 5px;
	}

	.contents {
		/* padding-top: 20upx;
		padding-bottom: 100upx;
		box-sizing: border-box; */
	}

	#signatureImg {
		background-color: #EEEEEE;
	}

	.caozuo {
		display: flex;
		height: 100upx;
		width: 750upx;
		position: fixed;
		left: 0;
		bottom: 0;
	}

	.caozuo view {
		width: 375upx;
		text-align: center;
		height: 100upx;
		line-height: 100upx;
		color: #FFFFFF;
	}

	.caozuo view:active {
		background-color: #CCCCCC;
		color: #333333;
	}

	.chongqian {
		background-color: #FF8F58;
	}

	.over {
		background-color: #0599D7;
	}

	.qm_btn button {
		font-size: 15px;
		width: 250rpx;
		margin-top: 15px;
	}

	.pop_body {
		/* height: 100vh; */
		padding: 5px;

	}

	.submit_btn button {
		font-size: 15px;
		width: 250rpx;
		margin-top: 15px;
	}

	.warn {
		font-size: 13px
	}

	.can {
		display: flex;
		justify-content: center;
	}

	.jSignature {
		margin: 10px 0px;
		display: flex;
		border: 1px dashed #aaa;
		/* max-width: 320px; */
		width: 100vw;
		height: 160px;
		/* max-height: 426px; */
		max-width: 380px;
		touch-action: none;
		background-color: rgb(246, 246, 246);
		display: block;
		outline: none;
	}
</style>
